﻿using System.Reflection;
using CommandLine;
using CommandLine.Text;

namespace VerifySigns
{
    public class Options
    {
        private readonly HeadingInfo _headingInfo;

        private static string exeName()
        {
            return Assembly.GetEntryAssembly().GetName().Name;
        }

        public Options()
        {
            _headingInfo = new HeadingInfo(string.Format("Crypton {0} - sign verification utility.", exeName()), 
                "Version "+Assembly.GetExecutingAssembly().GetName().Version.ToString());
        }

        [Option("s", "source", HelpText = "Source files mask. Wildcard (* and ?) symbols usage is allowed.", Required = true)]
        public string Source = "";

        [Option("p", "pubkeys", HelpText = "Public keys directory. Default value is VerifySigns.exe directory.")]
        public string PublicKeysDir = "";

        [Option("v", "verbose", HelpText = "Sign details output. Valid values id on and off. Default value is on.")]
        public string Verbose = "on";

        [HelpOption(HelpText = "Dispaly this help screen.")]
        public string GetUsage()
        {
            var help = new HelpText(_headingInfo)
                           {
                               AdditionalNewLineAfterOption = false,
                               Copyright = new CopyrightInfo("Vladimir V.Boborykin", 2010, 2011)
                           };
            help.AddPreOptionsLine(@"".PadRight(70, '-'));
            help.AddPreOptionsLine(string.Format(@"USAGE: {0} -s[ource] sourceMask [-p[ubkeys] publicKeysDirectory] [-v[erbose] on|off]", exeName()));

            help.AddPostOptionsLine(@"EXAMPLES:");
            help.AddPostOptionsLine(@" Verify sign for all files in c:\source directory:");
            help.AddPostOptionsLine(string.Format(@"  {0}.exe -s c:\source\*.*", exeName()));

            help.AddOptions(this);

            return help;
        }
    }
}
